package com.dbManage.tools;

import com.dbManage.entity.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionTool {
    public static HttpSession getSession() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        return session;
    }
    public static User getUser() {
        return (User) getSession().getAttribute("user");
    }
    public static void removeUser(){
        getSession().removeAttribute("user");
    }
    public static void setUser(User user){
        getSession().setAttribute("user",user);
    }
}
